﻿using System;
using System.Net;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace InteractiveMapApp
{
    public class Category
    {
        #region declare variables
        private int categoryID;
        public int CategoryID
        {
            get { return categoryID; }
            set { categoryID = value; }
        }

        private string categoryDesc;
        public string CategoryDesc
        {
            get { return categoryDesc; }
            set { categoryDesc = value; }
        }

        /// <summary>
        /// is it a story which only admin can use?
        /// </summary>
        /// 
        private bool adminStory;
        public bool AdminStory
        {
            get { return adminStory; }
            set { adminStory = value; }
        }

        private bool showFilter = true;
        public bool ShowFilter
        {
            get { return showFilter; }
            set { showFilter = value; }
        }

        private ImageSource markerImageSourceNormal;
        public ImageSource MarkerImageSourceNormal
        {
            get { return markerImageSourceNormal; }
            set { markerImageSourceNormal = value; }
        }

        private ImageSource categoryImageSourceSelected;
        public ImageSource CategoryImageSourceSelected
        {
            get { return categoryImageSourceSelected; }
            set { categoryImageSourceSelected = value; }
        }

        private ImageSource catImgSrcUNSelectedFilter;
        public ImageSource CatImgSrcUNSelectedFilter
        {
            get { return catImgSrcUNSelectedFilter; }
            set { catImgSrcUNSelectedFilter = value; }
        }

        private ImageSource catImgSELECTEDInputBox;
        public ImageSource CatImgSELECTEDInputBox
        {
            get { return catImgSELECTEDInputBox; }
            set { catImgSELECTEDInputBox = value; }
        }

        private ImageSource catImgUNSelectedInputBox;
        public ImageSource CatImgUNSelectedInputBox
        {
            get { return catImgUNSelectedInputBox; }
            set { catImgUNSelectedInputBox = value; }
        }

        private string filter_selectedImgURL;
        public string Filter_selectedImgURL
        {
            get { return filter_selectedImgURL; }
            set { filter_selectedImgURL = value; }
        }

        private string filter_unselectedImgURL;
        public string Filter_unselectedImgURL
        {
            get { return filter_unselectedImgURL; }
            set { filter_unselectedImgURL = value; }
        }

        private string input_selectedImgURL;
        public string Input_selectedImgURL
        {
            get { return input_selectedImgURL; }
            set { input_selectedImgURL = value; }
        }


        private string input_unselectedImgURL;
        public string Input_unselectedImgURL
        {
            get { return input_unselectedImgURL; }
            set { input_unselectedImgURL = value; }
        }

        private string markerImageURL;
        public string MarkerImageURL
        {
            get { return markerImageURL; }
            set { markerImageURL = value; }
        }

        #endregion

        /// <summary>
        /// creates categories
        /// </summary>
        /// <param name="catID">the id of the category</param>
        /// <param name="selected_filterImgUrl">the image representing the category</param>
        /// <param name="markerNormalImgUrl">the marker image representing the category</param>
        /// <param name = "admnStory">is it a category which only admin can use?</param>
        public Category(int catID, string catDesc, string selected_filterImgUrl, string markerNormalImgUrl, bool admnStory, string unselectedFilterImage, string img_selectedInputBox, string img_UNselectedInputbox)
        {
            this.categoryID = catID;
            this.categoryDesc = catDesc.Replace("`","'");//replaces the tilde (`) with a single quote (')
            this.adminStory = admnStory;
            this.filter_selectedImgURL = selected_filterImgUrl;
            this.filter_unselectedImgURL = unselectedFilterImage;
            this.input_selectedImgURL = img_selectedInputBox;
            this.input_unselectedImgURL = img_UNselectedInputbox;
            this.markerImageURL = markerNormalImgUrl;

            //categoryImageSourceNormal
            ImageSource catDisplayIconIncaseOriginalNotAvailable = new BitmapImage(new Uri("/InteractiveMapApp;component/Images/unavailableStoryIcon.png", UriKind.Relative));
            try
            {
                WebClient wcNormalImg = new WebClient();
                System.IO.Stream streamNormalImg = wcNormalImg.OpenRead(MainWindow.iconsStarterPath + selected_filterImgUrl);
                System.Drawing.Bitmap catImgNrml = new System.Drawing.Bitmap(streamNormalImg);
                this.categoryImageSourceSelected = Utility.GetImage(catImgNrml);
            }
            catch
            {
                this.categoryImageSourceSelected = catDisplayIconIncaseOriginalNotAvailable;
            }

            //markerImageSourceNormal
            try
            {
                WebClient wcMarkerNrml = new WebClient();
                System.IO.Stream streamMarkerNrml = wcMarkerNrml.OpenRead(MainWindow.iconsStarterPath + markerNormalImgUrl);
                System.Drawing.Bitmap markerImgNrml = new System.Drawing.Bitmap(streamMarkerNrml);
                this.markerImageSourceNormal = Utility.GetImage(markerImgNrml);
            }
            catch
            {
                this.markerImageSourceNormal = new BitmapImage(new Uri("/InteractiveMapApp;component/Cursors/pointer_empty.png", UriKind.Relative));
            }

            //catImgSrcSelectedFilter
            try
            {
                WebClient wc = new WebClient();
                System.IO.Stream stream = wc.OpenRead(MainWindow.iconsStarterPath + unselectedFilterImage);
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(stream);
                this.catImgSrcUNSelectedFilter = Utility.GetImage(bmp);
            }
            catch
            {
                this.catImgSrcUNSelectedFilter = catDisplayIconIncaseOriginalNotAvailable;
            }
            
            //catImgNormalInputBox
            try
            {
                WebClient wc2 = new WebClient();
                System.IO.Stream stream2 = wc2.OpenRead(MainWindow.iconsStarterPath + img_selectedInputBox);
                System.Drawing.Bitmap bmp2 = new System.Drawing.Bitmap(stream2);
                this.catImgSELECTEDInputBox = Utility.GetImage(bmp2);
            }
            catch
            {
                this.catImgSELECTEDInputBox = catDisplayIconIncaseOriginalNotAvailable;
            }

            //catImgSelectedInputBox
            try
            {
                WebClient wc3 = new WebClient();
                System.IO.Stream stream3 = wc3.OpenRead(MainWindow.iconsStarterPath + img_UNselectedInputbox);
                System.Drawing.Bitmap bmp3 = new System.Drawing.Bitmap(stream3);
                this.catImgUNSelectedInputBox = Utility.GetImage(bmp3);
            }
            catch
            {
                this.catImgUNSelectedInputBox = catDisplayIconIncaseOriginalNotAvailable;
            }
        }


        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}